// JavaScript Document
function validate(){
	
var empno = document.getElementById('txtEmpno');	
var un = document.getElementById('txtUn');	
var pw = document.getElementById('txtPw');	
var re =document.getElementById('txtRe');
var level=document.getElementById('sltLevel');

var pww = document.getElementById('txtPw').value;	
var ree =document.getElementById('txtRe').value;

if(notEmpty(empno, "Emp/Reg no cannot be empty")){
	if(isNumeric(empno, "Reg/Emp no should be numeric")){
   if(notEmpty(un,"User Name cannot be empty")){
	   if(notEmpty(pw, "password cannot be empty")){
		   if(notEmpty(re, "Retype cannot be empty")){
               if(madeSelection(level, "Select the Level")){
                        if(pww==ree){
							
							 loadXMLDoc()
							
							} else{
								
								alert("Can not matching password");
								
								}                       
                           
   
                          return false;

			         }
					 
                      return false;

		           }
				  
                    return false;
 
		        }
			
                return false;
	
            }
		
           return false;
	
         }
	return false;	 
}
return false;
} 

function loadXMLDoc()
{


if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("ajaxDiv").innerHTML=xmlhttp.responseText;
	document.getElementById("myForm").reset(); 
	
    }
  }

    
var level=document.getElementById('sltLevel').value;	
var empno = document.getElementById('txtEmpno').value;	
var unn = document.getElementById('txtUn').value;	
var pwn = document.getElementById('txtPw').value;	

var queryString ="?level=" + level +"&empno="+empno+ "&uname=" +unn +"&pword="+pwn;
	
xmlhttp.open("GET","../logic/add/user_add.php"+queryString ,true);
xmlhttp.send();
}


function checkregno(){

var empno = document.getElementById('txtEmpno');	
if(notEmpty(empno, "Emp/Reg no cannot be empty")){

 if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
    }
  else
   {// code for IE6, IE5
 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
    xmlhttp.onreadystatechange=function()
     {
 if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
									//document.getElementById("ajaxDiv").innerHTML=xmlhttp.responseText; 
									 
   var x=xmlhttp.responseText;
if(x=="false"){
									
  document.getElementById("ajaxDiv1").innerHTML="Invalid Input No";
  document.getElementById('txtEmpno').value="";
	}else{
  document.getElementById("ajaxDiv1").innerHTML=x; 
									
			}
			}
            }
								
  var y=document.getElementById('txtEmpno').value;
  var queryString ="?regno=" + y;
  xmlhttp.open("GET","../logic/load/check_reg_emp.php"+queryString,true);
  xmlhttp.send();	  
	
}
}
	

function checkusername(){

var un = document.getElementById('txtUn');
if(notEmpty(un,"User Name cannot be empty")){

 if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
    }
  else
   {// code for IE6, IE5
 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
    xmlhttp.onreadystatechange=function()
     {
 if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
									//document.getElementById("ajaxDiv").innerHTML=xmlhttp.responseText; 
									 
   var x=xmlhttp.responseText;
if(x=="false"){
									
  document.getElementById("ajaxDiv2").innerHTML="Existing User Name ";
  document.getElementById('txtUn').value="";
	}else{
  document.getElementById("ajaxDiv2").innerHTML=x; 
									
			}
			}
            }
								
  var y=document.getElementById('txtUn').value;
  var queryString ="?user=" + y;
  xmlhttp.open("GET","../logic/load/check_username.php"+queryString,true);
  xmlhttp.send();	  
	
	
}
}



		function clearx()
{
	
	 document.getElementById("myForm").reset(); 
     document.getElementById("ajaxDiv").innerHTML="";
	 document.getElementById("ajaxDiv1").innerHTML="";
	 document.getElementById("ajaxDiv2").innerHTML="";
}

